/*
 * 6位密码输入检测（4分）
 */

#include <stdio.h>

int main() {
	setbuf(stdout, NULL);

	char password[6];
	int index = 0, get_return = 0;

	// note: 提示用户输入
	printf("Input your password:\n");

	// 检测用户输入的合法性
	while (get_return != 1 || index <= 5) {
		get_return = scanf("%c", &password[index]);
		if (get_return == 1 &&
		    password[index] >= '0' &&
		    password[index] <= '9') {
			printf("%c, you have enter %d-bits number\n", password[index], index + 1);

			++index;

			// 清空缓冲区残留
			// while (getchar() != '\n');
			setbuf(stdin, NULL);
		} else {
			// 输出错误警告
			printf("error\n");

			// 对于输入异常的情况，清空缓冲区残留
			// while (getchar() != '\n');
			setbuf(stdin, NULL);
		}
	}

	return 0;
}